package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import cn.wolfcode.trip.base.util.JsonResult;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
/**
 * 推荐游记资源控制器
 */
@Controller
@RequestMapping("travelCommend")
public class TravelCommendController {
    @Autowired
    private ITravelCommendService travelCommendService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") TravelCommendQueryObject qo, Model model){
        model.addAttribute("pageInfo",travelCommendService.query(qo));
        return "travelCommend/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(MultipartFile file, TravelCommend travelCommend){
        JsonResult jsonResult = new JsonResult();
        if (file!=null && file.getSize()>0){
            //保存封面图片
            String url = UploadUtil.uploadQiniu(file);
            //把url设置到coverUrl属性
            travelCommend.setCoverUrl(url);
        }
        travelCommendService.saveOrUpdate(travelCommend);
        return jsonResult;
    }

    /*@RequestMapping("updateState")
    @ResponseBody
    public JsonResult updateState(Travel travel){
        JsonResult jsonResult = new JsonResult();
        if (travel.getState()==2){
            travel.setReleaseTime(new Date());
        }
        try {
            travelService.updateState(travel);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark("操作失败!");
        }
        return jsonResult;
    }*/

}
